package com.xqb.modules.controller.course;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.LesSubjectCategory;
import com.xqb.modules.service.ILesSubjectCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程分类关系Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/course/subject_category")
public class LesSubjectCategoryController extends BaseController
{
    @Autowired
    private ILesSubjectCategoryService lesSubjectCategoryService;

    /**
     * 查询课程分类关系列表
     */
    @PreAuthorize("@ss.hasPermi('course:subject_category:list')")
    @GetMapping("/list")
    public TableDataInfo list(LesSubjectCategory lesSubjectCategory)
    {
        startPage();
        List<LesSubjectCategory> list = lesSubjectCategoryService.selectLesSubjectCategoryList(lesSubjectCategory);
        return getDataTable(list);
    }

    /**
     * 导出课程分类关系列表
     */
    @PreAuthorize("@ss.hasPermi('course:subject_category:export')")
    @Log(title = "课程分类关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LesSubjectCategory lesSubjectCategory)
    {
        List<LesSubjectCategory> list = lesSubjectCategoryService.selectLesSubjectCategoryList(lesSubjectCategory);
        ExcelUtil<LesSubjectCategory> util = new ExcelUtil<LesSubjectCategory>(LesSubjectCategory.class);
        util.exportExcel(response, list, "课程分类关系数据");
    }

    /**
     * 获取课程分类关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:subject_category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lesSubjectCategoryService.selectLesSubjectCategoryById(id));
    }

    /**
     * 新增课程分类关系
     */
    @PreAuthorize("@ss.hasPermi('course:subject_category:add')")
    @Log(title = "课程分类关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LesSubjectCategory lesSubjectCategory)
    {
        return toAjax(lesSubjectCategoryService.insertLesSubjectCategory(lesSubjectCategory));
    }

    /**
     * 修改课程分类关系
     */
    @PreAuthorize("@ss.hasPermi('course:subject_category:edit')")
    @Log(title = "课程分类关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LesSubjectCategory lesSubjectCategory)
    {
        return toAjax(lesSubjectCategoryService.updateLesSubjectCategory(lesSubjectCategory));
    }

    /**
     * 删除课程分类关系
     */
    @PreAuthorize("@ss.hasPermi('course:subject_category:remove')")
    @Log(title = "课程分类关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lesSubjectCategoryService.deleteLesSubjectCategoryByIds(ids));
    }
}
